package cn.ulyer.generator.util;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Properties;

public class VelocityUtil {

    final static Properties p =new Properties();

    static {
        p.put("file.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init(p);
    }



    public  static String renderHtml(VelocityContext context , String template) throws IOException {
            StringWriter writer  = new StringWriter();
            Template velocity_template = Velocity.getTemplate(template,"utf8");
            velocity_template.merge(context,writer);
            String html = writer.toString();
            writer.close();
            return html;
    }


}
